package config

import "time"

type Cache struct {
	CacheType string `mapstructure:"cache_type" json:"cache_type" yaml:"cache_type"`
	Redis     *Redis `mapstructure:"redis" json:"redis" yaml:"redis"`
}

type Redis struct {
	// Default is tcp.
	Network string `mapstructure:"network" json:"network" yaml:"network"`
	// host:port address.
	Addr string `mapstructure:"addr" json:"addr" yaml:"addr"`

	// ClientName will execute the `CLIENT SETNAME ClientName` command for each conn.
	ClientName string `mapstructure:"client_name" json:"client_name" yaml:"redis"`

	Username string `json:"username" mapstructure:"username" yaml:"username"`
	// Optional password. Must match the password specified in the
	// requirepass server configuration option (if connecting to a Redis 5.0 instance, or lower),
	// or the User Password when connecting to a Redis 6.0 instance, or greater,
	// that is using the Redis ACL system.
	Password string `json:"password" mapstructure:"password" yaml:"password"`

	// Database to be selected after connecting to the server.
	DB int `json:"db" mapstructure:"db" yaml:"db"`

	// Maximum number of retries before giving up.
	// Default is 3 retries; -1 (not 0) disables retries.
	MaxRetries int `json:"max_retries" mapstructure:"max_retries" yaml:"max_retries"`

	// Dial timeout for establishing new connections.
	// Default is 5 seconds.
	DialTimeout time.Duration `json:"dial_timeout" mapstructure:"dial_timeout" yaml:"dial_timeout"`

	// Timeout for socket reads. If reached, commands will fail
	// with a timeout instead of blocking. Supported values:
	//   - `0` - default timeout (3 seconds).
	//   - `-1` - no timeout (block indefinitely).
	//   - `-2` - disables SetReadDeadline calls completely.
	ReadTimeout time.Duration `json:"read_timeout" mapstructure:"read_timeout" yaml:"read_timeout"`

	// Timeout for socket writes. If reached, commands will fail
	// with a timeout instead of blocking.  Supported values:
	//   - `0` - default timeout (3 seconds).
	//   - `-1` - no timeout (block indefinitely).
	//   - `-2` - disables SetWriteDeadline calls completely.
	WriteTimeout time.Duration `json:"write_timeout" mapstructure:"write_timeout" yaml:"write_timeout"`

	// Maximum number of socket connections.
	// Default is 10 connections per every available CPU as reported by runtime.GOMAXPROCS.
	PoolSize int `json:"pool_size" mapstructure:"pool_size" yaml:"pool_size"`

	// Minimum number of idle connections which is useful when establishing
	// new connection is slow.
	// Default is 0. the idle connections are not closed by default.
	MinIdleConns int `json:"min_idle_conns" mapstructure:"min_idle_conns" yaml:"min_idle_conns"`
	// Maximum number of idle connections.
	// Default is 0. the idle connections are not closed by default.
	MaxIdleConns int `json:"max_idle_conns" mapstructure:"max_idle_conns" yaml:"max_idle_conns"`
}
